<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 显示绑定：call  apply bind，这三个东西就是为了改变this 指向,基本用法
        function foo() {
            console.log(this)
        }

        let obj = {
            foo:foo
        }

        let bar = obj.foo

        bar();
        // call
        bar.call(obj)

        // apply
        bar.apply(obj)

        // bind
        bar.bind(obj)()


        // 区别在于函数需要传参时，方式不同
        function foo1(a, b) {
            console.log(a, b)
            console.log(this)
        }

        let obj1 = {
            foo1:foo1
        }

        let bar1 = obj1.foo1

        bar1(1, 2);
        // call
        bar1.call(obj1, 1, 2)

        // apply
        bar1.apply(obj1, [1, 2])

        // bind
        bar1.bind(obj1)(1, 2)


    </script>
</body>
</html>